package com.rjwh.dingdong.client.mvp.presenter.impl;

import android.content.Context;

import com.aishua.lib.task.AsResult;
import com.aishua.lib.utils.AsStrUtils;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.impl.MoreChangePasswordModel;
import com.rjwh.dingdong.client.mvp.presenter.IMoreChangePasswordPresenter;
import com.rjwh.dingdong.client.mvp.view.MoreChangePasswordView;
import com.rjwh.dingdong.client.util.ToastUtil;

/**
 * @author Kay
 * @ClassName MoreChangePasswordPresenter
 * @Description
 * @date 2016-10-19
 * @history 2016-10-19 author: description:
 */

public class MoreChangePasswordPresenter extends BasePresenter<MoreChangePasswordView> implements IMoreChangePasswordPresenter {

    private MoreChangePasswordModel model;

    public MoreChangePasswordPresenter(Context context, MoreChangePasswordView mMvpView) {
        super(context, mMvpView);
        model = new MoreChangePasswordModel(this);
    }

    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {
        if (isViewAttached()) {
            getMvpView().dismissLoading();
            switch (businessType) {
                case NetConstant.UPDATEPWD:
                    if (mAsResult.getResultCode() > NetConstant.MSG_CONNECT_SUCCESS) {
                        ToastUtil.showToast(getContext(), "密码已修改!");
                        getMvpView().LoadData();
                    } else if (!AsStrUtils.isEmpty(mAsResult.getResultMsg())) {
                        ToastUtil.showToast(getContext(), mAsResult.getResultMsg());
                    }
                    break;

                default:
                    break;
            }
        }
    }

    @Override
    public void detachView() {
        model.detachView();
        detachViews();
    }

    @Override
    public void doUpdatePwd(String oldpwd, String newpwd) {
        if (isViewAttached()) {
            getMvpView().showLoading();
            model.doUpdatePwd(oldpwd, newpwd);
        }
    }
}
